import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/components/pages/home/Home'
import Login from '@/components/pages/Login/Login'
import meetingroom from '@/components/pages/meeting_room/meetinghome'
import createroom from '@/components/pages/create_room/createroom'
import setEvents from '@/components/pages/set_Events/setEvents'
Vue.use(Router)

const router=new Router({
  routes: [
    {
      path: '/index',
      name: 'Home',
      component: Home
    }, {
      path: '/login',
      name: 'Login',
      component: Login
    }, {
      path: '/enter_room',
      name: 'meetingroom',
      component: meetingroom
    }, {
      path: '/create_room',
      name: 'createroom',
      component: createroom
    }, {
      path: '/set_Events',
      name: 'setEvents',
      component: setEvents
    }
  ]
})
router.beforeEach((to, from, next) => {
  //NProgress.start();
  if (to.path == '/login') {
    sessionStorage.removeItem('userId');
    sessionStorage.removeItem('token');
    sessionStorage.removeItem('roomIdList');
  }
  //let user = JSON.parse(sessionStorage.getItem('user'));
  let user = sessionStorage.getItem('userId');
  if (!user && to.path != '/login') {
    next({ path: '/login' })
  } else {
    next()
  }
})
export default router;
